/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package Util;

import Database.ConnectToDatabase;
import java.sql.*;
import java.util.*;

/**
 *
 * @author PhucTakua
 */
public class Department {

    private int iddepartment;
    private String namedepartment;

    public Department() {
    }

    /**
     * @return the iddepartment
     */
    public int getIddepartment() {
        return iddepartment;
    }

    /**
     * @param iddepartment the iddepartment to set
     */
    public void setIddepartment(int iddepartment) {
        this.iddepartment = iddepartment;
    }

    /**
     * @return the namedepartment
     */
    public String getNamedepartment() {
        return namedepartment;
    }

    /**
     * @param namedepartment the namedepartment to set
     */
    public void setNamedepartment(String namedepartment) {
        this.namedepartment = namedepartment;
    }

    public boolean AddDepartment() {
        return CommonQuery.Command("insert into Department values('" + this.namedepartment + "')");
    }

    public boolean UpdateDepartment() {
        return CommonQuery.Command("update Department set namedepartment = '" + this.namedepartment + "' where iddepartment='" + this.iddepartment + "' ");
    }

    public boolean DeleteDepartment() {
        return CommonQuery.Command("delete Department where iddepartment='" + this.iddepartment + "'");
    }

    public Vector<Department> ListIDD() {
        Vector<Department> listd = new Vector<Department>();
        try {
            Connection con = ConnectToDatabase.getConnection();
            String query = "select * from Department";
            Statement st = con.createStatement();
            ResultSet rs = st.executeQuery(query);
            while (rs.next()) {
                Department d = new Department();
                d.setIddepartment(rs.getInt("iddepartment"));
                d.setNamedepartment(rs.getString("namedepartment"));
                listd.add(d);
            }
        } catch (Exception e) {
            listd = null;
        }
        return listd;
    }
}
